reducer default 返回 state

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { resetShare } from 'utils/wxUtil'

const initialData = {
shareStatus: false,
goods: {}
}

export default function (state = initialData, action) {
switch (action.type) {
case 'SHARE_SHOW':
return {
shareStatus: true,
goods: action.goods
}
case 'SHARE_HIDE':
resetShare()
return {
shareStatus: false,
goods: {}
}
default:
return state
}
}

所有action都会进入default,此时一定要回传state

坚持原创技术分享,您的支持将鼓励我继续创作!